<?php

/**
 * @file
 * Administration interface for the module, basically the selection of contexts
 * and the changing of names.
 */

/**
 * The administration form, which settings for context extend.
 */
function context_extend_admin_form() {
  $form = array();

  $form['context_extend_allow_user_edit_context'] = array(
    '#type' => 'checkbox',
    '#title' => t('Allow user to edit current context'),
    '#default_value' => variable_get('context_extend_allow_user_edit_context', FALSE),
  );

  // Find all modules that implements hook_block
  $options = array();
  foreach (module_implements('block_info') as $module) {
    $options[$module] = $module;
  }

  // Build admin form
  $form['context_extend_block_types'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Context drop down types'),
    '#options' => $options,
    '#default_value' => variable_get('context_extend_block_types', $options),
  );

  return system_settings_form($form);
}

/**
 * Administration form for chaning the group drop-down names in context.
 *
 * @return array $form
 */
function context_extend_names_admin_form() {
  $form = array(
    '#tree' => TRUE,
  );

  // Load the selected modules that provides blocks or show all modules that
  // provides blocks.
  $options = variable_get('context_extend_block_types', array());
  if (!$options) {
    $options = array_filter($options);
    foreach (module_implements('block') as $module) {
      $options[$module] = $module;
    }
  }

  // Load default values.
  $default = variable_get('context_extend_names', array());

  // Build form elements.
  foreach ($options as $value) {
    $form['context_extend_names'][$value] = array(
      '#type' => 'textfield',
      '#title' => $value,
      '#default_value' => isset($default[$value]) ? $default[$value] : $value,
      '#description' => t('Change the name displayed in the context drop-down box.'),
    );
  }

  return system_settings_form($form);
}